#include<bits/stdc++.h>
using namespace std;
int T,a[100005],n;
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		int ans=0;
		scanf("%d",&n);
		for(int i=0;i<n;i++)scanf("%d",&a[i]);
		for(int i=0;i<(1<<n);i++){
			int s=0;
			for(int j=0;j<n;j++){
				int c=((i>>j)&1);
				int k=j+1;
				while(((i>>k)&1)!=c&&k<n)k++;
				if(a[k]==a[j])s+=a[j];
			}
			ans=max(s,ans);
		}
		printf("%d\n",ans);
	}
}

